
package com.epro.dx.task;

import android.os.AsyncTask;

import com.epro.dx.listenner.MyAsyncTaskListenner;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.weipu.common.constants.Constant;
import com.weipu.common.facade.exception.DxException;
import com.weipu.common.facade.impl.BaseServiceProviderImpl;
import com.weipu.common.facade.model.FeedBackModel;
import com.weipu.common.facade.model.Parmars;

import org.json.JSONObject;

public class FeedBackTask extends AsyncTask<Void, Void, String> {
    private MyAsyncTaskListenner myAsyncTaskListenner;

    private String  email;
    private String Content;

    private FeedBackModel respone;

    public FeedBackTask(String  email, String Content,
                        MyAsyncTaskListenner myAsyncTaskListenner) {
        this.email = email;
        this.Content = Content;
        this.myAsyncTaskListenner = myAsyncTaskListenner;

    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        if (myAsyncTaskListenner != null) {
            myAsyncTaskListenner.onPostTask(result, respone);
        }
    }

    @Override
    protected String doInBackground(Void... params) {
        try {
            respone = new CreateFeedBackImpl().create(email,
                    Content);
        } catch (DxException e) {
            return e.getErrCode();
        }
        return "0";
    }

    public class CreateFeedBackImpl extends BaseServiceProviderImpl {

        public FeedBackModel create(String  email, String Content)
                throws DxException {

            Parmars parmars = new Parmars();
            parmars.setEmail(email);
            parmars.setContent(Content);
            parmars.setClientType("1");
            JSONObject jsonObject = requestHttpPostData(Constant.CREATEFEEDBACK_URL,parmars);
            GsonBuilder gsonBuilder = new GsonBuilder();
            Gson gson = gsonBuilder.create();
            return gson.fromJson(jsonObject.toString(), FeedBackModel.class);
        }

    }


}
